package com.contain.minio.service;

import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.errors.*;
import io.minio.http.Method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @Auther: tianchao
 * @Date: 2021/8/22 11:25
 * @Description:
 */
@Service
public class PresignedOperationsService {
    @Autowired
    private MinioClient minioClient;
    public String presignedGetObject(){
        String url =
                null;
        try {
            url = minioClient.getPresignedObjectUrl(
                    GetPresignedObjectUrlArgs.builder()
                            .method(Method.GET)
                            .bucket("dockerminio")
                            .object("test111.png")
                            .expiry(60 * 60 * 24)
                            .build());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(url);
        return url;
    }
    public String presignedPutObject (){
        String url =
                null;
        try {
            url = minioClient.getPresignedObjectUrl(
                    GetPresignedObjectUrlArgs.builder()
                            .method(Method.GET)
                            .bucket("dockerminio")
                            .object("test111.png")
                            .expiry(60 * 60 * 24)
                            .build());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(url);
        return url;
    }
}
